"""
lasted edited at 2018-4-23 by Stone
1.The method to construct the shape of the objects is so complicated, and the data to specify the shape of objects
is rather more, so I separate them here.
2."xx" class in main code is correspondingly named "xxShape" here.
3.All the unit of length is meter.

data source:
    car: https://wenku.baidu.com/view/f6a7573a67ec102de3bd890f.html
    bus: https://wenku.baidu.com/view/06e54dd6b9f3f90f76c61bec.html
"""


class CarShape:

    def __init__(self):pass
    shape = {
        "car": {"length": 4.6, "width": 1.7, "height": 1.4},
        "bus": {"length": 12.0, "width":2.5, "height": 3.3}
    }


class Car:

    def make_shape(self, frame):
        self.f = frame  # the frame is visual.frame object
        for idx in self.bricks:
            self.bricks[idx] = box(color=self.color, frame=self.f,
                                    length=self.brickLength, width=self.brickThickness, height=self.brickHeight,
                                   )
            if idx[0] == 'f' or idx[0] == 'b': self.bricks[idx].rotate(angle=pi/2, axis=self.f.up)

        ogn_fm = pos(0, self.brickHeight, -half(self.brickLength)-self.width)
        self.bricks["fl"].pos = (ogn_fm[0]-self.width-self.brickThickness, ogn_fm[1], ogn_fm[2])
        self.bricks["fm"].pos = ogn_fm
        self.bricks["fr"].pos = (ogn_fm[0]+self.width+self.brickThickness, ogn_fm[1], ogn_fm[2])
        ogn_bm = ogn_fm + pos(0, 0, self.brickLength+2*self.width)
        self.bricks["bl"].pos = (ogn_bm[0]-self.width-self.brickThickness, ogn_bm[1], ogn_bm[2])
        self.bricks["bm"].pos = ogn_bm
        self.bricks["br"].pos = (ogn_bm[0]+self.width+self.brickThickness, ogn_bm[1], ogn_bm[2])
        ogn_lm = pos(-half(self.brickLength)-self.width, self.brickHeight, 0)
        self.bricks["lf"].pos = (ogn_lm[0], ogn_lm[1], ogn_lm[2]-self.width-self.brickThickness)
        self.bricks["lm"].pos = ogn_lm
        self.bricks["lb"].pos = (ogn_lm[0], ogn_lm[1], ogn_lm[2]+self.width+self.brickThickness)
        ogn_rm = ogn_lm + pos(self.brickLength+2*self.width, 0, 0)
        self.bricks["rf"].pos = (ogn_rm[0], ogn_rm[1], ogn_rm[2]-self.width-self.brickThickness)
        self.bricks["rm"].pos = ogn_rm
        self.bricks["rb"].pos = (ogn_rm[0], ogn_rm[1], ogn_rm[2]+self.width+self.brickThickness)
